package br.com.sgmf.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import br.com.sgmf.dao.PecaDAO;
import br.com.sgmf.model.Peca;

@Service
public class PecaService {

	@Autowired
	private PecaDAO pecaDAO;

	public void saveOrUpdate(Peca peca) {
		if (peca.getId() == null) {
			pecaDAO.save(peca);
		} else {
			pecaDAO.update(peca);
		}
	}

	public void delete(Peca peca) {
		pecaDAO.delete(peca);
	}

	public Peca findById(Integer id) {
		return pecaDAO.findById(id);
	}

	public List<Peca> findAll() {
		return pecaDAO.findAll();
	}

	public List<Peca> findByNome(String nome) {
		return pecaDAO.findByNome(nome);
	}

	public List<Peca> findByNomeAndModelo(String nome, String modelo) {
		return pecaDAO.findByNomeAndModelo(nome, modelo);
	}
}
